<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="common/include :: header('物品基本信息列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <input type="hidden" id="categoryId" name="categoryId"><!--ztree数据-->

                <div class="select-list">
                    <ul>
                        <li>
                            关键字：<input type="text" placeholder="名称/品牌/规格/描述" name="Keyword"/>
                        </li>
                        <li>
                            仓库：
                            <select name="storeId">
                                <option value="">请选择</option>
                                <option th:each="store : ${stores}" th:text="${store.storeName}" th:value="${store.id}" >
                                </option>
                            </select>
                        </li>
                        <li>
                            <div class="form-group">
                                <div class="col-sm-8">
                                    <div class="btn-group">
                                        <button type="button" onclick="read()" class="btn btn-default dropdown-toggle" id="categoryName" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                            分类：<span class="caret"></span>
                                        </button>
                                        <ul id="treeDemo" class="ztree dropdown-menu"></ul>
                                    </div>
                                </div>
                            </div>
                        <li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:post:add">
                <i class="fa fa-plus"></i> 添加物品
            </a>
            <a class="btn btn-warning" onclick="storePage()">
                <i class="fa fa-plus"></i> 仓库管理
            </a>
            <a class="btn btn-info" onclick="categoryPage()" >
                <i class="fa fa-plus"></i> 分类管理
            </a>
            <a class="btn btn-success multiple disabled" onclick="$.operate.goodsToBill()">
                <i class="fa fa-remove"></i> 批量添加
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="common/include :: footer"/>
<th:block th:include="common/include :: datetimepicker" />
<th:block th:include="common/include :: ztree" /> <!--ztree下拉框树状结构插件-->

<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:post:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:post:remove')}]];
    var datas = [[${@dict.getType('sys_normal_disable')}]];
    var prefix = ctx + "/business/goods";
    var storeId=[[${storeId}]]==null?'':[[${storeId}]];
    $(function () {
        var options = {
            url: prefix + "/query?storeId=" + storeId,
            createUrl: prefix + "/addPage",
            updateUrl: prefix + "/editPage?id={id}",
            removeUrl: prefix + "/remove",
            goodsToBillUrl:prefix + "/goodsToBill",
            modalName: "物品基本信息",
            columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '序号',
                    visible: true
                },
                {
                    field: 'goodsCover',
                    title: '物品封面',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return '<img width="40" height="40" data-original="'+ encodeURI(value) +'" src="'+ encodeURI(value) +'">';
                    }
                },

                {
                    field: 'goodsName',
                    title: '物品名称',
                    sortable: true
                },
                {
                    field: 'brand',
                    title: '品牌',
                    sortable: true
                },
                {
                    field: 'goodsCategory.categoryName',
                    title: '所属分类',
                    sortable: true
                },
                {
                    field: 'spec',
                    title: '规格',
                    sortable: true
                },
                {
                    field: 'price',
                    title: '价格',
                    sortable: true
                },
                {
                    field: 'amounts',
                    title: '数量',
                    sortable: true
                },
                {
                    field: 'goodsDesc',
                    title: '描述',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs id="edit" '  + editFlag + '" href="javascript:void(0)" ' +
                            'onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');

                        actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" ' +
                            'onclick=" $.operate.goodsToBill(\'' + row.id + '\')"><i class="fa fa-plus"></i>添加物品到清单</a> ');

                        actions.push('<a class="btn btn-warning btn-xs " href="#"  onclick="detail()">出入库明细</a> ');

                        if (row.amounts == 0 || row.amounts == null){
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)"' +
                                ' onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }

                        return actions.join('');
                    }
                }]

        };
        $.table.init(options);
    });

    // 仓库管理页面跳转
    function storePage() {
        $.modal.openTab("仓库管理","/business/store/listPage");
    }
    // 分类管理页面跳转
    function categoryPage() {
        $.modal.openTab("分类管理","/business/goodsCategory/listPage");
    }

    // 出入库明细
    function detail() {
        $.modal.openTab("出入库明细","/business/stockBill/listPage");
    }

    function goodsToBill(id) {
        window.location.href = "/business/goods/goodsToBill?id=" + id
    }

    // 点击添加当前行信息到 stock_bill_item



    /*分类下拉框*/
    function read(){
        $.get("/business/goodsCategory/treeData", function (result) {
            // zTree 的参数配置，深入使用请参考 API 文档（setting 配置详解）
            console.log(result.data);
            var setting = {
                callback:{
                    onClick:function (a,b,data) {
                        console.log(data);
                        $('#categoryId').val(data.id);
                        $('#categoryName').html(data.categoryName);
                    }
                },
                data: {
                    key:{
                        name:'categoryName'
                    },
                    simpleData: {
                        enable: true,
                        idKey: "id",
                        pIdKey: "parentId",
                        rootPId: null
                    }
                }
            };

            // zTree 的数据属性，深入使用请参考 API 文档（zTreeNode 节点数据详解）
            var zTreeObj = $.fn.zTree.init($("#treeDemo"), setting, result.data);
            zTreeObj.expandAll(true);
        })
    }

    /*重置按钮点击事件*/
    function reset() {
        $('#categoryId').val('')
        $.form.reset()
    }

</script>
</body>
</html>